<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base],
  components: {},
  data() {
    return {
      load: true,
      form: {
        freightRule: 1, // 运费组合策略  写死
        isOpen: 1, //是否开启
        isDefaultFreight: 0, // 是否是默认配送方式 0否 1是
        freightType: 3, //类型 1商家配送 2同城限时达 3到店自提  写死
      },
      // 页面接口地址
      apiUrl: {
        detail: "mall-site-portal/freight-setting/getItem",
        save: "mall-site-portal/freight-setting/saveOrUpdate",
      },
    };
  },
  methods: {
    // 初始化
    init() {
      this.getData();
    },

    // 获取内容信息
    async getData() {
      this.load = true;
      let _data = await this.$vFN.Http.post(
        {
          url: this.apiUrl.detail,
          data: {
            freightType: 3, //写死
          },
        },
        window
      );
      if (_data._ok) {
        for (let i in this.form) {
          if (!this.$vFN.Utils.isEmpty(_data.data[i])) {
            this.form[i] = _data.data[i];
          }
        }
      }
      this.load = false;
    },

    // 验证
    validate() {
      return new Promise((resolve, reject) => {
        this.$refs["editForm"].validate((valid) => {
          valid ? resolve(true) : resolve(false);
        });
      });
    },
    // 提交
    async submit() {
      if (!(await this.validate())) {
        return;
      }
      this.load = true;
      let _data = await this.$vFN.Http.post(
        {
          url: this.apiUrl.save,
          data: this.form,
        },
        window
      );
      if (_data._ok) {
        this.$vFN.Tools.messageSuccess("操作成功");
        this.init();
      }
      this.load = false;
    },
  },
  mounted() {
    this.init();
  },
  activated() {},
};
</script>